// #ifndef VUE3
import Vue from 'vue'
import App from './App'
// import moment from 'moment'
// Vue.filter('dataFromat',(dataStr,pattern= 'YYYY-DD-MM HH:mm:ss')=>{
// 	return moment(dataStr).format(pattern)
// })
import uView from '@/uni_modules/uview-ui'
import {
	get,
	post,
	upload
} from '@/utils/request.js'
Vue.config.productionTip = false
App.mpType = 'app'


Vue.prototype.https = 'https://20240202xhfpeizhenxiaochengxu.rchz.top'
// Vue.prototype.https = 'https://pz.jzshangmen.cn'
import {
	gotopage
} from './common/gotopage.js'

Vue.prototype.topBarTop = function() {
	// #ifdef MP-WEIXIN
	return uni.getMenuButtonBoundingClientRect().top;
	// #endif
	// #ifndef MP-WEIXIN
	const SystemInfo = uni.getSystemInfoSync();
	return SystemInfo.statusBarHeight;
	// #endif
};
Vue.prototype.gotoPage = gotopage;
Vue.prototype.get = get;
Vue.prototype.post = post;
Vue.prototype.upload = upload;

Vue.use(uView)
const app = new Vue({
	...App
})
// console.log(this.showError,'-------------')
// Vue.filter('dateFormat', function(originVal) {
//   const dt = new Date(originVal)
//   const y = dt.getFullYear()
//   const m = (dt.getMonth() + 1 + '').padStart(2, '0')
//   const d = (dt.getDate() + '').padStart(2, '0')
//   const hh = (dt.getHours() + '').padStart(2, '0')
//   const mm = (dt.getMinutes() + '').padStart(2, '0')
//   const ss = (dt.getSeconds() + '').padStart(2, '0')
//   //时间格式年月日、时分秒
//   return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
// })
Vue.filter('dateFormate', function(originVal) {
	const dt = new Date(originVal)
	const y = dt.getFullYear()
	const m = (dt.getMonth() + 1 + '').padStart(2, '0')
	const d = (dt.getDate() + '').padStart(2, '0')
	const hh = (dt.getHours() + '').padStart(2, '0')
	const mm = (dt.getMinutes() + '').padStart(2, '0')
	const ss = (dt.getSeconds() + '').padStart(2, '0')
	return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
//时间格式年月日、时分秒  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`})
Vue.prototype.time_zhaunhuan = function(originVal) {
	const dt = new Date(originVal)
	const y = dt.getFullYear()
	const m = (dt.getMonth() + 1 + '').padStart(2, '0')
	const d = (dt.getDate() + '').padStart(2, '0')
	const hh = (dt.getHours() + '').padStart(2, '0')
	const mm = (dt.getMinutes() + '').padStart(2, '0')
	const ss = (dt.getSeconds() + '').padStart(2, '0')
	return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}

//get请求
Vue.prototype._get = function(path, data, success, fail, complete) {
	data = data || {};
	data.user_id = uni.getStorageSync('userID') || '';
	uni.request({
		url: this.https + path,
		data: data,
		dataType: 'json',
		method: 'GET',
		success: (res) => {
			if (res.statusCode !== 200 || typeof res.data !== 'object') {
				return false;
			}
			if (res.data.code === -2) {
				// this.showError(res.data.msg, function() {
					uni.removeStorageSync('token');
					this.gotoPage('/pages/index/index', 'reLaunch');
				// })
			} else if (res.data.code === -1) {
				// 登录态失效, 重新登录
				console.log('登录态失效, 重新登录');
				this.isLogin();
			} else if (res.data.code === 0) {
				// this.showError(res.data.msg, function() {
				// 	fail && fail(res);
				// });
				return false;
			} else {
				success && success(res.data);
			}
		},
		fail: (res) => {
			fail && fail(res);
		},
		complete: (res) => {
			uni.hideLoading();
			complete && complete(res);
		},
	});
};
Vue.prototype._post = function(path, data, success, fail, complete) {
	data = data || {};
	data.user_id = uni.getStorageSync('user_id') || '';
	uni.request({
		url: this.https + path,
		data: data,
		dataType: 'json',
		method: 'POST',
		header: {
			'tokne': uni.getStorageSync('token')
		},
		success: (res) => {
			if (res.data.code == 1) {
				success && success(res.data);
			}
		},
		fail: (res) => {
			fail && fail(res);
		},
		complete: (res) => {
			uni.hideLoading();
			complete && complete(res);
		},
	});
};
Vue.prototype.doLogin = function() {
	let pages = getCurrentPages();
	// let  pages2 = pages[0].$page.fullPath
	uni.switchTab({
		url: "/pages/My/My"
	})
};
Vue.prototype.isLogin = function() {
	if (uni.getStorageSync('token')) {
		return false
	} else {
		uni.switchTab({
			url: "/pages/My/My"
		})
	}
}


app.$mount()
// #endif
// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import App from './App.vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif